home *** CD-ROM | disk | FTP | other *** search
- class Player extends smashing.Renderable
- {
- var update;
- var halfR;
- var fruitSounds;
- var hangSounds;
- var pointSounds;
- var oGerms;
- var tempM;
- var x;
- var y;
- var cHurt;
- var a;
- var oSwing;
- var lastPos;
- var lastElapsed;
- var oCitizens;
- var shadow;
- var oBuildings;
- var nStartHurt;
- var onEnterFrame;
- var mcInvul;
- var aCritters;
- var camera;
- var oWorld;
- var upThrust = 1700;
- var sideThrust = 300;
- var r = 50;
- var xm = 0;
- var ym = 0;
- var jumpm = 0;
- var ySpeedLimit = 500;
- var onSurface = false;
- var nHurtFlash = 0.1;
- var nHurtTime = 2;
- var bHurt = false;
- var cGerms = 0;
- var facing = 1;
- var floorMod = 50;
- var germScore = 5;
- var nInvul = 5;
- var cInvul = 0;
- var bInvul = false;
- var nSpeed = 0;
- var nSpeedBoost = 150;
- var nSpeedTime = 5;
- var cSpeedTime = 0;
- var nHang = 10;
- var cHang = 0;
- var nCrouchMod = 0;
- var nIdle = 10;
- var cIdle = 0;
- var sIdle = "";
- var bSpaceDown = false;
- function Player()
- {
- super();
- this.update = this.updatePrompt;
- this.floorMod += this.r;
- this.halfR = this.r / 2;
- this.cGerms = 0;
- this.fruitSounds = ["las_fruitas","fruitas","fruit"];
- this.hangSounds = ["its_rescue_pack","wheee","were_flying"];
- this.pointSounds = ["bonus_points","bonus"];
- }
- function get germs()
- {
- return this.cGerms;
- }
- function updateGround(nElapsed)
- {
- var _loc8_ = undefined;
- var _loc4_ = "stand";
- var _loc10_ = false;
- if(this.nSpeed == 1)
- {
- this.cSpeedTime += nElapsed;
- _loc8_ = 0;
- if(Key.isDown(39))
- {
- _loc8_ += nElapsed * (this.sideThrust + this.nSpeedBoost);
- this.faceRight();
- _loc4_ = "run";
- }
- if(Key.isDown(37))
- {
- _loc8_ -= nElapsed * (this.sideThrust + this.nSpeedBoost);
- this.faceLeft();
- _loc4_ = "run";
- }
- if(this.cSpeedTime >= this.nSpeedTime)
- {
- this.unSpeed();
- }
- }
- else
- {
- _loc8_ = 0;
- if(Key.isDown(39))
- {
- _loc8_ += nElapsed * this.sideThrust;
- this.faceRight();
- _loc4_ = "run";
- }
- if(Key.isDown(37))
- {
- _loc8_ -= nElapsed * this.sideThrust;
- this.faceLeft();
- _loc4_ = "run";
- }
- }
- if(Key.isDown(38) || Key.isDown(32))
- {
- if(this.onSurface == true)
- {
- this.jumpm -= this.upThrust;
- }
- if(this.jumpm < 0)
- {
- this.jumpm += smashing.Phys.gr * nElapsed;
- }
- else
- {
- this.jumpm = 0;
- this.ym += smashing.Phys.gr * nElapsed;
- }
- this.bSpaceDown = true;
- }
- else
- {
- this.jumpm = 0;
- this.ym += smashing.Phys.gr * nElapsed;
- this.bSpaceDown = false;
- }
- if(Key.isDown(40))
- {
- this.onSurface = false;
- _loc10_ = true;
- }
- if(Math.abs(this.jumpm) > this.ySpeedLimit)
- {
- this.jumpm = this.ySpeedLimit * (this.jumpm / Math.abs(this.jumpm));
- }
- var _loc5_ = this.oGerms.oHandler.clips;
- var _loc7_ = _loc5_.length;
- var _loc2_ = undefined;
- var _loc15_ = undefined;
- var _loc14_ = new smashing.Point(0,0);
- var _loc3_ = 0;
- while(_loc3_ < _loc7_)
- {
- _loc2_ = _loc5_[_loc3_];
- if(_loc2_ != null)
- {
- if(_loc2_.grabbable == true)
- {
- if(_loc2_.checkHit(this))
- {
- _loc2_.react(this);
- }
- }
- }
- _loc3_ = _loc3_ + 1;
- }
- if(m.y > this.halfR)
- {
- m.y = this.halfR;
- }
- this.tempM = null;
- var _loc11_ = this.checkCollisions(nElapsed,_loc8_,_loc10_,false);
- var m = this.tempM;
- var _loc13_ = new smashing.Point(this.x,this.y);
- var _loc12_ = BuildingHandler.floor - this.floorMod;
- if(this.y + m.y > _loc12_)
- {
- this.y = _loc12_;
- this.ym = 0;
- this.jumpm = 0;
- m.y = 0;
- this.onSurface = true;
- _loc11_ = true;
- if(_loc10_ == true)
- {
- _loc4_ = "crouch";
- }
- }
- if(_loc11_ == false)
- {
- if(this.ym > 0)
- {
- _loc4_ = "jumpDown";
- }
- else
- {
- _loc4_ = "jumpUp";
- }
- }
- var _loc9_ = smashing.Viewport.halfWidth - this.r;
- if(this.x + m.x - smashing.Viewport.x < - _loc9_)
- {
- this.x = smashing.Viewport.x - _loc9_;
- m.x = 0;
- this.xm = 0;
- }
- if(this.x + m.x - smashing.Viewport.x > _loc9_)
- {
- this.x = smashing.Viewport.x + _loc9_;
- m.x = 0;
- this.xm = 0;
- }
- this.y += m.y;
- this.x += m.x;
- if(this.bHurt == true)
- {
- if(this.cHurt < this.nHurtTime / 2)
- {
- _loc4_ = "hit";
- }
- }
- this.a.gotoAndStop(_loc4_);
- if(this.nSpeed == 1)
- {
- this.a.blur._visible = true;
- }
- else
- {
- this.a.blur._visible = false;
- }
- }
- function updateHangPre(nElapsed)
- {
- this.a.gotoAndStop("hangStart");
- }
- function updateHang(nElapsed)
- {
- var _loc8_ = undefined;
- var _loc10_ = false;
- if(this.nSpeed == 1)
- {
- this.cSpeedTime += nElapsed;
- _loc8_ = 0;
- if(Key.isDown(39))
- {
- _loc8_ += nElapsed * (this.sideThrust + this.nSpeedBoost);
- this.faceRight();
- }
- if(Key.isDown(37))
- {
- _loc8_ -= nElapsed * (this.sideThrust + this.nSpeedBoost);
- this.faceLeft();
- }
- if(this.cSpeedTime >= this.nSpeedTime)
- {
- this.unSpeed();
- }
- }
- else
- {
- _loc8_ = 0;
- if(Key.isDown(39))
- {
- _loc8_ += nElapsed * this.sideThrust;
- this.faceRight();
- }
- if(Key.isDown(37))
- {
- _loc8_ -= nElapsed * this.sideThrust;
- this.faceLeft();
- }
- }
- if(Key.isDown(38) || Key.isDown(32))
- {
- this.ym -= this.upThrust * nElapsed;
- this.onSurface = false;
- }
- if(Key.isDown(40))
- {
- this.ym += this.upThrust * nElapsed;
- this.onSurface = false;
- _loc10_ = true;
- }
- this.ym += (smashing.Phys.gr - 200) * nElapsed;
- if(Math.abs(this.ym) > this.ySpeedLimit)
- {
- this.ym = this.ySpeedLimit * (this.ym / Math.abs(this.ym));
- }
- var _loc6_ = this.oGerms.oHandler.clips;
- var _loc7_ = _loc6_.length;
- var _loc2_ = undefined;
- var _loc16_ = undefined;
- var _loc15_ = new smashing.Point(0,0);
- var _loc3_ = 0;
- while(_loc3_ < _loc7_)
- {
- _loc2_ = _loc6_[_loc3_];
- if(_loc2_ != null)
- {
- if(_loc2_.grabbable == true)
- {
- if(_loc2_.pCurrLength == undefined)
- {
- if(_loc2_.checkHit(this))
- {
- _loc2_.react(this);
- }
- }
- }
- }
- _loc3_ = _loc3_ + 1;
- }
- this.tempM = null;
- var _loc13_ = this.checkCollisions(nElapsed,_loc8_,_loc10_,true);
- var _loc4_ = this.tempM;
- var _loc14_ = new smashing.Point(this.x,this.y);
- var _loc12_ = BuildingHandler.floor - this.floorMod;
- if(this.y + _loc4_.y > _loc12_)
- {
- this.y = _loc12_;
- this.ym = 0;
- this.jumpm = 0;
- _loc4_.y = 0;
- this.onSurface = true;
- _loc13_ = true;
- }
- var _loc11_ = BuildingHandler.ceiling + this.r;
- if(this.y + _loc4_.y < _loc11_)
- {
- this.ym = 0;
- this.jumpm = 0;
- _loc4_.y = 0;
- this.y = _loc11_;
- }
- var _loc9_ = smashing.Viewport.halfWidth - this.r;
- if(this.x + _loc4_.x - smashing.Viewport.x < - _loc9_)
- {
- this.x = smashing.Viewport.x - _loc9_;
- _loc4_.x = 0;
- this.xm = 0;
- }
- if(this.x + _loc4_.x - smashing.Viewport.x > _loc9_)
- {
- this.x = smashing.Viewport.x + _loc9_;
- _loc4_.x = 0;
- this.xm = 0;
- }
- this.y += _loc4_.y;
- this.x += _loc4_.x;
- if(this.bHurt == true)
- {
- if(this.cHurt < this.nHurtTime / 2)
- {
- }
- }
- this.a.gotoAndStop("hang");
- if(this.nSpeed == 1)
- {
- this.a.blur._visible = true;
- }
- else
- {
- this.a.blur._visible = false;
- }
- this.cHang += nElapsed;
- if(this.cHang >= this.nHang)
- {
- this.unHang();
- }
- }
- function updatePrompt(nElapsed)
- {
- var _loc10_ = undefined;
- var _loc6_ = "stand";
- var _loc12_ = false;
- if(this.nSpeed == 1)
- {
- this.cSpeedTime += nElapsed;
- _loc10_ = 0;
- if(Key.isDown(39))
- {
- _loc10_ += nElapsed * (this.sideThrust + this.nSpeedBoost);
- this.faceRight();
- _loc6_ = "run";
- this.update = this.updateGround;
- }
- if(Key.isDown(37))
- {
- _loc10_ -= nElapsed * (this.sideThrust + this.nSpeedBoost);
- this.faceLeft();
- _loc6_ = "run";
- this.update = this.updateGround;
- }
- if(this.cSpeedTime >= this.nSpeedTime)
- {
- this.unSpeed();
- }
- }
- else
- {
- _loc10_ = 0;
- if(Key.isDown(39))
- {
- _loc10_ += nElapsed * this.sideThrust;
- this.faceRight();
- _loc6_ = "run";
- this.update = this.updateGround;
- }
- if(Key.isDown(37))
- {
- _loc10_ -= nElapsed * this.sideThrust;
- this.faceLeft();
- _loc6_ = "run";
- this.update = this.updateGround;
- }
- }
- if(Key.isDown(38) || Key.isDown(32))
- {
- if(this.onSurface == true)
- {
- this.jumpm -= this.upThrust;
- }
- if(this.jumpm < 0)
- {
- this.jumpm += smashing.Phys.gr * nElapsed;
- }
- else
- {
- this.jumpm = 0;
- this.ym += smashing.Phys.gr * nElapsed;
- }
- this.bSpaceDown = true;
- this.update = this.updateGround;
- }
- else
- {
- this.jumpm = 0;
- this.ym += smashing.Phys.gr * nElapsed;
- this.bSpaceDown = false;
- }
- if(Key.isDown(40))
- {
- this.onSurface = false;
- _loc12_ = true;
- this.update = this.updateGround;
- }
- if(Math.abs(this.jumpm) > this.ySpeedLimit)
- {
- this.jumpm = this.ySpeedLimit * (this.jumpm / Math.abs(this.jumpm));
- }
- var _loc8_ = this.oGerms.oHandler.clips;
- var _loc9_ = _loc8_.length;
- var _loc4_ = undefined;
- var _loc17_ = undefined;
- var _loc16_ = new smashing.Point(0,0);
- var _loc5_ = 0;
- while(_loc5_ < _loc9_)
- {
- _loc4_ = _loc8_[_loc5_];
- if(_loc4_ != null)
- {
- if(_loc4_.grabbable == true)
- {
- if(_loc4_.checkHit(this))
- {
- _loc4_.react(this);
- }
- }
- }
- _loc5_ = _loc5_ + 1;
- }
- if(m.y > this.halfR)
- {
- m.y = this.halfR;
- }
- this.tempM = null;
- var _loc13_ = this.checkCollisions(nElapsed,_loc10_,_loc12_,false);
- var m = this.tempM;
- var _loc15_ = new smashing.Point(this.x,this.y);
- var _loc14_ = BuildingHandler.floor - this.floorMod;
- if(this.y + m.y > _loc14_)
- {
- this.y = _loc14_;
- this.ym = 0;
- this.jumpm = 0;
- m.y = 0;
- this.onSurface = true;
- _loc13_ = true;
- if(_loc12_ == true)
- {
- _loc6_ = "crouch";
- }
- }
- if(_loc13_ == false)
- {
- if(this.ym > 0)
- {
- _loc6_ = "jumpDown";
- }
- else
- {
- _loc6_ = "jumpUp";
- }
- }
- var _loc11_ = smashing.Viewport.halfWidth - this.r;
- if(this.x + m.x - smashing.Viewport.x < - _loc11_)
- {
- this.x = smashing.Viewport.x - _loc11_;
- m.x = 0;
- this.xm = 0;
- }
- if(this.x + m.x - smashing.Viewport.x > _loc11_)
- {
- this.x = smashing.Viewport.x + _loc11_;
- m.x = 0;
- this.xm = 0;
- }
- this.y += m.y;
- this.x += m.x;
- if(this.bHurt == true)
- {
- if(this.cHurt < this.nHurtTime / 2)
- {
- _loc6_ = "hit";
- }
- }
- _root.nDebug1 = this.cIdle;
- this.cIdle += nElapsed;
- if(this.cIdle >= this.nIdle)
- {
- this.cIdle = 0;
- _global.oSound.playSnd("time_out_use_keys");
- }
- this.a.gotoAndStop(_loc6_);
- if(this.nSpeed == 1)
- {
- this.a.blur._visible = true;
- }
- else
- {
- this.a.blur._visible = false;
- }
- }
- function updateHangPost(nElapsed)
- {
- this.a.gotoAndStop("hangLand");
- }
- function updateSwing(nElapsed)
- {
- var _loc9_ = this.oSwing.hitLength * this.oSwing.hitLength / this.oSwing.pCurrLength.dot(this.oSwing.pCurrLength);
- var _loc5_ = this.oSwing.pCurrLength.multiply(_loc9_);
- _loc5_.x += this.oSwing.x;
- _loc5_.y += this.oSwing.y;
- this.x = _loc5_.x;
- this.y = _loc5_.y;
- var _loc7_ = false;
- if(Key.isDown(32) || Key.isDown(38))
- {
- if(this.bSpaceDown == false)
- {
- _loc7_ = true;
- this.xm = (_loc5_.x - this.lastPos.x) / nElapsed * 2;
- this.ym = (_loc5_.y - this.lastPos.y) / nElapsed * 2;
- this.oSwing.cDisable = 0;
- this.oSwing.bSwung = false;
- this.update = this.updateGround;
- }
- }
- else
- {
- this.lastPos = _loc5_;
- this.lastElapsed = nElapsed;
- this.bSpaceDown = false;
- }
- if(this.bHurt == false)
- {
- var _loc4_ = this.oCitizens.oHandler.clips;
- var _loc8_ = _loc4_.length;
- var _loc2_ = undefined;
- var _loc3_ = 0;
- while(_loc3_ < _loc8_)
- {
- _loc2_ = _loc4_[_loc3_];
- if(_loc2_ != null)
- {
- if(_loc2_.bDead == false)
- {
- if(_loc2_.collisionTest(this) == true)
- {
- if(_loc7_ == false)
- {
- this.oSwing.cDisable = 0;
- this.oSwing.bSwung = false;
- this.update = this.updateGround;
- }
- _loc2_.react(this,nElapsed);
- }
- }
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- this.a.gotoAndStop("vine");
- }
- function checkCollisions(nElapsed, nXm, bCrouch, bHang)
- {
- if(this.bHurt == false)
- {
- var _loc11_ = this.oCitizens.oHandler.clips;
- var _loc12_ = _loc11_.length;
- var _loc5_ = undefined;
- var _loc8_ = 0;
- while(_loc8_ < _loc12_)
- {
- _loc5_ = _loc11_[_loc8_];
- if(_loc5_ != null)
- {
- if(_loc5_.bDead == false)
- {
- if(_loc5_.collisionTest(this) == true)
- {
- _loc5_.react(this,nElapsed);
- }
- }
- }
- _loc8_ = _loc8_ + 1;
- }
- }
- this.xm -= smashing.Phys.drag(this.xm,nElapsed);
- if(this.xm > -20)
- {
- this.xm = 0;
- }
- nXm += this.xm * nElapsed;
- var _loc18_ = (this.ym + this.jumpm) * nElapsed;
- this.shadow._x = this._x + nXm;
- this.shadow._y = this._y + _loc18_;
- var _loc6_ = new smashing.Point(nXm,_loc18_);
- var _loc9_ = new smashing.Point(this.x,this.y);
- _loc11_ = this.oBuildings.oHandler.clips;
- _loc12_ = _loc11_.length;
- var _loc10_ = undefined;
- var _loc4_ = undefined;
- var _loc22_ = [];
- var _loc2_ = undefined;
- var _loc7_ = null;
- var _loc13_ = [];
- if(bHang != true)
- {
- _loc8_ = 0;
- while(_loc8_ < _loc12_)
- {
- _loc5_ = _loc11_[_loc8_];
- if(_loc5_.hasObstacle == true)
- {
- if(_loc5_.hitTest(this) == true || _loc5_.hitTest(this.shadow) == true)
- {
- _loc4_ = _loc5_.aLines;
- _loc10_ = _loc4_.length;
- var _loc3_ = 0;
- while(_loc3_ < _loc10_)
- {
- if(bCrouch == false)
- {
- if(_loc6_.y > 20)
- {
- _loc2_ = _loc4_[_loc3_].collisionPointSwept(_loc9_,_loc6_,this.r);
- }
- else
- {
- _loc2_ = _loc4_[_loc3_].collisionPointThresh(_loc9_,_loc6_,this.r);
- }
- }
- else if(!smashing.Misc.isHoriz(_loc4_[_loc3_]))
- {
- _loc2_ = _loc4_[_loc3_].collisionPointThresh(_loc9_,_loc6_,this.r);
- }
- _loc13_.push(_loc2_);
- if(_loc7_ == null && _loc2_ != null)
- {
- _loc7_ = _loc2_;
- }
- else if(_loc2_.distSqu < _loc7_.distSqu && _loc2_ != null)
- {
- _loc7_ = _loc2_;
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- }
- _loc8_ = _loc8_ + 1;
- }
- }
- var _loc17_ = false;
- if(_loc7_ != null)
- {
- var _loc20_ = Math.sqrt(_loc7_.distSqu);
- _loc6_.length -= _loc20_;
- var _loc19_ = _loc7_.gizmo.lineNormal;
- this.onSurface = true;
- _loc17_ = true;
- var _loc16_ = new smashing.Point(_loc7_.hit.x,_loc7_.hit.y);
- this.x = _loc16_.x;
- this.y = _loc16_.y;
- _loc9_ = new smashing.Point(this.x,this.y);
- _loc6_ = _loc19_.multiply(_loc6_.dot(_loc19_));
- if(_loc6_.y == 0)
- {
- this.ym = 0;
- this.jumpm = 0;
- }
- if(_loc6_.x == 0)
- {
- this.xm = 0;
- }
- }
- else
- {
- this.onSurface = false;
- }
- this.tempM = _loc6_;
- return _loc17_;
- }
- function setBuilding(o, c, g)
- {
- this.oBuildings = o;
- this.oCitizens = c;
- this.oGerms = g;
- }
- function setShadow(mc)
- {
- this.shadow = mc;
- this.shadow._width = this.r * 2;
- this.shadow._height = this.r * 2;
- }
- function render()
- {
- var _loc2_ = smashing.Viewport.getPos(this);
- this._x = _loc2_.x + smashing.Viewport.centerX;
- this._y = _loc2_.y + smashing.Viewport.centerY;
- }
- function hurt()
- {
- _global.oSound.playSnd("upon_hit",40);
- var _loc3_ = new smashing.Point(-3,-2);
- _loc3_.length = 700;
- this.xm = _loc3_.x;
- this.ym = _loc3_.y;
- this.bHurt = true;
- this.nStartHurt = getTimer();
- this.onEnterFrame = function()
- {
- this.cHurt = (getTimer() - this.nStartHurt) / 1000;
- if(this.cHurt >= this.nHurtTime)
- {
- this._visible = true;
- this.bHurt = false;
- delete this.onEnterFrame;
- }
- };
- }
- function invulnerable()
- {
- this.bInvul = true;
- this.mcInvul._visible = true;
- }
- function unInvulnerable()
- {
- this.bInvul = false;
- this.cInvul = 0;
- this.mcInvul._visible = false;
- }
- function speed()
- {
- this.nSpeed = 1;
- this.cSpeedTime = 0;
- _global.oSound.playSnd(smashing.Misc.rndElement(this.fruitSounds));
- _global.oSound.playSnd("bonus_speed",60);
- }
- function unSpeed()
- {
- this.nSpeed = 0;
- }
- function getGerm(g)
- {
- this.aCritters.push(g.sCrit);
- _global.mcRoot.mcMenu.setCritters(this.aCritters);
- this.cGerms = this.cGerms + 1;
- DiegoWorld.addScore(this.germScore);
- _global.mcRoot.oBase.pause();
- this.camera._visible = true;
- this.camera.sCritter = g.sCrit;
- this.camera.mcCritter = g;
- this.a.a.stop();
- this.a.blur.stop();
- this.camera.play();
- }
- function removeGerm()
- {
- this.cGerms = this.cGerms - 1;
- if(this.cGerms < 0)
- {
- this.cGerms = 0;
- }
- }
- function reset()
- {
- this.aCritters = [];
- this.a.gotoAndStop("stand");
- this.x = smashing.Viewport.x - this.oWorld.playerOffset;
- this.y = BuildingHandler.floor - this.r * 3;
- this.cGerms = 0;
- this.bHurt = false;
- delete this.onEnterFrame;
- this._visible = true;
- this.xm = 0;
- this.ym = 0;
- this.jumpm = 0;
- this.nSpeed = 0;
- this.update = this.updateGround;
- this.a.gotoAndStop("stand");
- this.faceRight();
- this.render();
- }
- function faceLeft()
- {
- this.gotoAndStop("left");
- this.facing = -1;
- }
- function faceRight()
- {
- this.gotoAndStop("right");
- this.facing = 1;
- }
- function hang()
- {
- _global.oSound.playSnd("rescupack_pickup");
- _global.oSound.playSnd(smashing.Misc.rndElement(this.hangSounds));
- this.update = this.updateHangPre;
- this.xm = 0;
- this.ym = 0;
- this.cHang = 0;
- }
- function unHang()
- {
- this.a.gotoAndStop("hangLand");
- this.update = this.updateHangPost;
- }
- function swing(o)
- {
- this.oSwing = o;
- this.update = this.updateSwing;
- }
- function addScore(n)
- {
- _global.oSound.playSnd("bonus_coin",60);
- _global.oSound.playSnd(smashing.Misc.rndElement(this.pointSounds));
- this.oWorld.score += n;
- }
- }
-